<?php

class ControllerCommonHome extends Controller {

    public function index() {
        $this->load->model('catalog/product');
        $this->load->model('tool/seo_url');
        $this->load->model('tool/image');
        $this->document->setTitle($this->config->get('config_title'));
        $this->document->setDescription($this->config->get('config_meta_description'));

        $this->data['heading_title'] = $this->config->get('config_title');

        

        //------- get category show to home page -----------------------
        $category = $this->model_catalog_product->getCategoryAndProduct();

        if (count($category) > 0) {
            foreach ($category as $key => $value) {
                $category[$key]['href'] = $this->model_tool_seo_url->rewrite($this->model_tool_seo_url->http('product/category&path=' . $value['category_id']));
                foreach ($value['products'] as $k => $v) {
                    $category[$key]['products'][$k]['href'] = $this->model_tool_seo_url->rewrite($this->model_tool_seo_url->http('product/product&path=' . $this->model_tool_seo_url->khongdau($category[$key]['name']) . '&product_id=' . $v['product_id']));
                    $category[$key]['products'][$k]['img'] = $this->model_tool_image->resize($v['image'], 150, 160);
                }
            }
            $this->data['category'] = $category;
        }
        
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/home.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/common/home.tpl';
        } else {
            $this->template = 'default/template/common/home.tpl';
        }

        $this->children = array(
            'common/column_left',
            'common/column_right',
            'common/content_top',
            'common/content_bottom',
            'common/footer',
            'common/header'
        );

        $this->response->setOutput($this->render());
    }

}

?>